import DataBus from '../databus'
import DActionItem from '../d_a_item'

const screenWidth  = window.innerWidth
const screenHeight = window.innerHeight
const Restart_IMG_SRC = 'images/restart.png'
const Share_IMG_SRC = 'images/share.png'
const End_IMG_SRC = 'images/end_bg.png'

let databus = new DataBus()
let diamondSize = databus.diamondSize

export default class GameInfo {
  constructor() {
    
    this.end_height = (databus.line_num - 2) * 40 / 56;
    this.end_y = (databus.c_height - this.end_height) / 2;
    this.end_bg = new DActionItem(End_IMG_SRC, 1, this.end_y, databus.line_num - 2, this.end_height, 6);

    this.restart = new DActionItem(Restart_IMG_SRC, 5, this.end_y + this.end_height - 5, 3, 3, 4);
    this.share = new DActionItem(Share_IMG_SRC, databus.line_num - 8, this.end_y + this.end_height - 5, 3, 3, 5);
    

  }
  
  renderGameOver(ctx, score) {
    
    this.end_bg.drawToCanvas(ctx)
    this.restart.drawToCanvas(ctx)
    this.share.drawToCanvas(ctx)

    ctx.fillStyle = "#ffffff"
    ctx.font    = "30px Arial"
    ctx.fillText(
      score,
      screenWidth / 2 - 20,
      (this.end_y + 4) * diamondSize
    )
  }

  touchMonitor(x,y){
    let is_restart = this.restart.touch(x,y)
    if (is_restart) {
      databus.reset()
      return;
    }

    let is_share = this.share.touch(x, y)
    if (is_share) {
      wx.shareAppMessage({"title":"快来一起玩啊"})
      return;
    }
  }
}

